package org.tloss.web.editor.model.command;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlSeeAlso;

@XmlSeeAlso({ If.class, Else.class })
public abstract class ComplexCommand extends Command implements
		IGeneratorWithTowFactor {
	List<Command> commands;

	public void addCommand(Command command) {
		if (commands == null) {
			commands = new ArrayList<Command>();
		}
		commands.add(command);
	}

	public void removeCommand(Command command) {
		if (commands != null) {
			commands.remove(command);
		}
	}

	public void moveUpCommand(Command command) {
		if (commands != null) {
			int index = commands.indexOf(command);
			if (index != 0) {
				Command tmp = commands.get(index - 1);
				commands.set(index - 1, command);
				commands.set(index, tmp);
			}
		}
	}

	public List<Command> getCommands() {
		return commands;
	}

	public void setCommands(List<Command> commands) {
		this.commands = commands;
	}

	@Override
	public List<Command> getChildren() {
		return commands;
	}

}
